<?php
// 更改信息
header("content-type:text/html;charset=utf-8");
include_once("conn.php");

// 更改基本信息
$action = $_POST['action'];

if($action == 'baseinfo'){
    $u_id = $_POST['u_id'];
    $u_name = $_POST['u_name'];
    $u_phone = $_POST['u_phone'];
    $sql = "UPDATE tb_user SET u_name = '".$u_name."',  u_phone = '".$u_phone."' WHERE u_id = '".$u_id."'";
    if(mysqli_query($conn_DB,$sql)){
        echo "<script>alert('修改成功！即将退出登录！');</script>";
        include_once("logout.php");
    }else{
        echo "<script>alert('修改失败！请重试！');history.go(-1);</script>";
    }
}

// 更改登录密码
if($action == 'password'){
    session_start();
    $u_id = $_POST['u_id'];
    $u_oldpwd = $_POST['old_pwd'];
    $u_password = $_POST['new_pwd'];
    if($u_oldpwd != $_SESSION['USER']['u_password']){
        echo $_SESSION['USER']['u_password'];
        echo $u_password;
        die("<script>alert('修改失败！原始密码错误！');</script>");
    }
    $sql = "UPDATE tb_user SET u_password = '".$u_password."' WHERE u_id = '".$u_id."'";
    if(mysqli_query($conn_DB,$sql)){
        echo "<script>alert('修改成功！即将重新登录！');</script>";
        include_once("logout.php");
    }else{
        echo "<script>alert('修改失败！请重试！');history.go(-1);</script>";
    }
}
